



// This code is a generated code by a tool
// designed and coded by Shohdi Mohamed Elsheemy ( shohdi@gmail.com )            

using System;
using System.Collections.Generic;
using System.Web;
using System.Data.Common;
using Shohdi.DataHandler;
using System.Data;




namespace DatabaseComponent
{
    
    public partial class ForgottedPasswordsDB
    {
         string _Connection = "";


        public string Connection
        {
            get { return _Connection; }
            set { _Connection = value; }
        }


       
         string _Provider = "System.Data.SqlClient";

        
        public string Provider
        {
            get { return _Provider; }
            set { _Provider = value; }
        }



        public ForgottedPasswordsDB()
        {
        }

        public ForgottedPasswordsDB(string __Connection,params string [] __Provider)
        {

            if (__Provider.Length > 0)
                _Provider = __Provider[0];

            _Connection = __Connection;
            
        }




        public List<ForgottedPasswords> Select(ClassDataHandler con, string strTop, string strWhere, params DbParameter[] whereParams)
        {
            if (whereParams == null)
                whereParams = new DbParameter[0];

            List<ForgottedPasswords> lstRet = new List<ForgottedPasswords>();

            string strQuery = " select " + strTop  + " * from dbo.[ForgottedPasswords]  " ;

            if (strWhere != "")
            {
                strQuery = strQuery + "  " + strWhere;
            }

            DbDataReader dr = con.SelectDataReader(strQuery, CommandType.Text, whereParams);


            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    ForgottedPasswords obj = new ForgottedPasswords();
 if (dr["ID"] != DBNull.Value)
                    {
                        obj.ID = (System.Int64)dr["ID"];
                    }
                    else
                    {
                        obj.ID = -1;
                    } 
 if (dr["PersonID"] != DBNull.Value)
                    {
                        obj.PersonID = (System.Int64)dr["PersonID"];
                    }
                    else
                    {
                        obj.PersonID = -1;
                    } 
 if (dr["GeneratedID"] != DBNull.Value)
                    {
                        obj.GeneratedID = (System.String)dr["GeneratedID"];
                    }
                    else
                    {
                        obj.GeneratedID = "";
                    } 



                    lstRet.Add(obj);
                   

                }
            }

            dr.Close();


            return lstRet;
        }


        public List<ForgottedPasswords> Select(string strTop, string strWhere, params DbParameter[] whereParams)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<ForgottedPasswords> lstRet = Select(con, strTop, strWhere, whereParams);

            con.CloseConnection();

            return lstRet;
        }

        



        public void Insert(ClassDataHandler con , ForgottedPasswords obj)
        {
            
            

                    DbParameter prmPersonID = con.createParameter();
                    prmPersonID.ParameterName = "@PersonID";
                    prmPersonID.DbType =DbType.Int64;
                    if (obj.PersonID == null)
                    {
                        prmPersonID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmPersonID.Value = obj.PersonID;
                    }
                

                    


                    DbParameter prmGeneratedID = con.createParameter();
                    prmGeneratedID.ParameterName = "@GeneratedID";
                    prmGeneratedID.DbType =DbType.String;
                    if (obj.GeneratedID == null)
                    {
                        prmGeneratedID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmGeneratedID.Value = obj.GeneratedID;
                    }
                

                    


           



            string strQuery = " insert into dbo.[ForgottedPasswords] ([PersonID],[GeneratedID]) VALUES (@PersonID,@GeneratedID) ; select SCOPE_IDENTITY() ";
 object scope = con.ExecuteScalar(strQuery, CommandType.Text, prmPersonID,prmGeneratedID);


                    try
                    {
                        obj.ID = System.Int64.Parse(scope.ToString());
                    }
                    catch
                    {
                        obj.ID = -1;
                    }


                    


           

        }



        public void Insert(ForgottedPasswords obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
            con.OpenConnection();

            Insert(con,obj);


            con.CloseConnection();
        }




        public void Update(ClassDataHandler con, ForgottedPasswords obj)
        {
            
            

                    DbParameter prmID = con.createParameter();
                    prmID.ParameterName = "@ID";
                    prmID.DbType =DbType.Int64;
                    if (obj.ID == null)
                    {
                        prmID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmID.Value = obj.ID;
                    }
                

                    


                    DbParameter prmPersonID = con.createParameter();
                    prmPersonID.ParameterName = "@PersonID";
                    prmPersonID.DbType =DbType.Int64;
                    if (obj.PersonID == null)
                    {
                        prmPersonID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmPersonID.Value = obj.PersonID;
                    }
                

                    


                    DbParameter prmGeneratedID = con.createParameter();
                    prmGeneratedID.ParameterName = "@GeneratedID";
                    prmGeneratedID.DbType =DbType.String;
                    if (obj.GeneratedID == null)
                    {
                        prmGeneratedID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmGeneratedID.Value = obj.GeneratedID;
                    }
                

                    


           



            string strQuery = " update dbo.[ForgottedPasswords] set [PersonID]=@PersonID,[GeneratedID]=@GeneratedID where  [ID]=@ID  ";

            con.ExecuteNonQuery(strQuery, CommandType.Text,prmID,prmPersonID,prmGeneratedID);

            

        }


        public void Update(ForgottedPasswords obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
            con.OpenConnection();

            Update(con, obj);


            con.CloseConnection();
        }



        public void Delete(ClassDataHandler con, ForgottedPasswords obj)
        {

            

                    DbParameter prmID = con.createParameter();
                    prmID.ParameterName = "@ID";
                    prmID.DbType =DbType.Int64;
                    if (obj.ID == null)
                    {
                        prmID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmID.Value = obj.ID;
                    }
                

                    


           



           



            string strQuery = " delete from dbo.[ForgottedPasswords]  where  [ID]=@ID  "; 
                        con.ExecuteNonQuery(strQuery, CommandType.Text,prmID );  

             



        }


        public void Delete( ForgottedPasswords obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            Delete(con, obj);

            con.CloseConnection();
        }





                    public List<ForgottedPasswords> getForgottedPasswordsByID(ClassDataHandler con,System.Int64 ID)
                    {
                        List<ForgottedPasswords> lstRet = new List<ForgottedPasswords>();


                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType = DbType.Int64;
                        if (ID == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmID.Value = ID;
                        }


                        lstRet = Select(con, "" , " where [ID]=@ID ", prmID);



                        return lstRet;

                    }


                    public List<ForgottedPasswords> getForgottedPasswordsByID(System.Int64 ID)
                    {
                        List<ForgottedPasswords> lstRet = new List<ForgottedPasswords>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getForgottedPasswordsByID(con, ID);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<ForgottedPasswords> getForgottedPasswordsByPersonID(ClassDataHandler con,System.Int64 PersonID)
                    {
                        List<ForgottedPasswords> lstRet = new List<ForgottedPasswords>();


                        DbParameter prmPersonID = con.createParameter();
                        prmPersonID.ParameterName = "@PersonID";
                        prmPersonID.DbType = DbType.Int64;
                        if (PersonID == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmPersonID.Value = PersonID;
                        }


                        lstRet = Select(con, "" , " where [PersonID]=@PersonID ", prmPersonID);



                        return lstRet;

                    }


                    public List<ForgottedPasswords> getForgottedPasswordsByPersonID(System.Int64 PersonID)
                    {
                        List<ForgottedPasswords> lstRet = new List<ForgottedPasswords>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getForgottedPasswordsByPersonID(con, PersonID);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<ForgottedPasswords> getForgottedPasswordsByGeneratedID(ClassDataHandler con,System.String GeneratedID)
                    {
                        List<ForgottedPasswords> lstRet = new List<ForgottedPasswords>();


                        DbParameter prmGeneratedID = con.createParameter();
                        prmGeneratedID.ParameterName = "@GeneratedID";
                        prmGeneratedID.DbType = DbType.String;
                        if (GeneratedID == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmGeneratedID.Value = GeneratedID;
                        }


                        lstRet = Select(con, "" , " where [GeneratedID]=@GeneratedID ", prmGeneratedID);



                        return lstRet;

                    }


                    public List<ForgottedPasswords> getForgottedPasswordsByGeneratedID(System.String GeneratedID)
                    {
                        List<ForgottedPasswords> lstRet = new List<ForgottedPasswords>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getForgottedPasswordsByGeneratedID(con, GeneratedID);

                        con.CloseConnection();

                        return lstRet;

                    }



                

            
public List<ForgottedPasswords> Search(ClassDataHandler con, ForgottedPasswords obj)
        {
            string strWhere = "";
            List<DbParameter> lstParameters = new List<DbParameter>();

            
                    if (obj.ID != -1)
                    {
                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType =DbType.Int64;
                        if (obj.ID == null)
                        {
                            prmID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmID.Value = obj.ID;
                        }
                        strWhere += " [ID]=@ID AND ";
                        lstParameters.Add(prmID);
                     }



                    

                    if (obj.PersonID != -1)
                    {
                        DbParameter prmPersonID = con.createParameter();
                        prmPersonID.ParameterName = "@PersonID";
                        prmPersonID.DbType =DbType.Int64;
                        if (obj.PersonID == null)
                        {
                            prmPersonID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmPersonID.Value = obj.PersonID;
                        }
                        strWhere += " [PersonID]=@PersonID AND ";
                        lstParameters.Add(prmPersonID);
                     }



                    

                    if (obj.GeneratedID != "")
                    {
                        DbParameter prmGeneratedID = con.createParameter();
                        prmGeneratedID.ParameterName = "@GeneratedID";
                        prmGeneratedID.DbType =DbType.String;
                        if (obj.GeneratedID == null)
                        {
                            prmGeneratedID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmGeneratedID.Value = obj.GeneratedID;
                        }
                        strWhere += " [GeneratedID]=@GeneratedID AND ";
                        lstParameters.Add(prmGeneratedID);
                     }



                    


            if (strWhere != "")
                        strWhere = " where " + strWhere.Substring(0, strWhere.LastIndexOf("AND"));

                    

            

            List<ForgottedPasswords> lstRet = Select(con, "", strWhere, lstParameters.ToArray());

            return lstRet;
        }


        public List<ForgottedPasswords> Search(ForgottedPasswords obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<ForgottedPasswords> lstRet = Search(con,obj);

            con.CloseConnection();

            return lstRet;
        }


                

            
public List<ForgottedPasswords> SearchOrLike(ClassDataHandler con, ForgottedPasswords obj)
        {
            string strWhere = "";
            List<DbParameter> lstParameters = new List<DbParameter>();

            
                    if (obj.ID != -1)
                    {
                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType =DbType.Int64;
                        if (obj.ID == null)
                        {
                            prmID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmID.Value = obj.ID;
                        }
                        strWhere += " [ID]=@ID OR ";
                        lstParameters.Add(prmID);
                     }



                    

                    if (obj.PersonID != -1)
                    {
                        DbParameter prmPersonID = con.createParameter();
                        prmPersonID.ParameterName = "@PersonID";
                        prmPersonID.DbType =DbType.Int64;
                        if (obj.PersonID == null)
                        {
                            prmPersonID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmPersonID.Value = obj.PersonID;
                        }
                        strWhere += " [PersonID]=@PersonID OR ";
                        lstParameters.Add(prmPersonID);
                     }



                    

                    if (obj.GeneratedID != "")
                    {
                        DbParameter prmGeneratedID = con.createParameter();
                        prmGeneratedID.ParameterName = "@GeneratedID";
                        prmGeneratedID.DbType =DbType.String;
                        if (obj.GeneratedID == null)
                        {
                            prmGeneratedID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmGeneratedID.Value = obj.GeneratedID;
                        }
                        strWhere += " [GeneratedID] LIKE @GeneratedID OR ";
                        lstParameters.Add(prmGeneratedID);
                     }



                    


            if (strWhere != "")
                        strWhere = " where " + strWhere.Substring(0, strWhere.LastIndexOf("OR"));

                    

            

            List<ForgottedPasswords> lstRet = Select(con, "", strWhere, lstParameters.ToArray());

            return lstRet;
        }


        public List<ForgottedPasswords> SearchOrLike(ForgottedPasswords obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<ForgottedPasswords> lstRet = SearchOrLike(con,obj);

            con.CloseConnection();

            return lstRet;
        }


                
        


       
        



    }
}











            